Purpose |
Add a text box control to a dialog. A text box is very similar to a conventional edit control, and it is used to enter text into an application. Text boxes support single-line and multiple-line input. |
||||||||||||||||||||||||||||||||||||||
Syntax |
CONTROL ADD TEXTBOX, hDlg, id&, txt$, x, y, xx, yy [, [style&] [, [exstyle&]]] [[,] CALL callback] |
||||||||||||||||||||||||||||||||||||||
hDlg |
Handle of the dialog in which the text box will be created. The dialog will become the parent of the control. |
||||||||||||||||||||||||||||||||||||||
Unique identifier for the control in the range 1 to 65535, frequently specified with numeric equates for clarity of the code. For example, the equate %CustomerName is more informative than a literal value such as 497. Best practice suggests identifiers should start at 100 to avoid conflict with any of the standard predefined identifiers. |
|||||||||||||||||||||||||||||||||||||||
txt$ |
Default text to be displayed in text box. txt$ may be a string, string equate, or string expression. txt$ can be empty if there is no default text. |
||||||||||||||||||||||||||||||||||||||
x, y |
Integer expressions, variables, or numeric literal values, specifying the location of the control inside the dialog client area. x is the horizontal position, and y is the vertical position. 0,0 refers to the upper left corner of the dialog box client area. Coordinates are specified in the same terms (pixels or dialog units) as the parent dialog. |
||||||||||||||||||||||||||||||||||||||
Integral expression, variable, or numeric literal value, specifying the width of the control. The width is given in the same terms (pixels or dialog units) as the parent dialog. The most common value used in the Microsoft Dialog Editor and Visual Studio is 100 dialog units. |
|||||||||||||||||||||||||||||||||||||||
yy |
Integral expression, variable, or numeric literal value, specifying the height of the control. The height is given in the same terms (pixels or dialog units) as the parent dialog. The most common value used in the Microsoft Dialog Editor and Visual Studio is 12 dialog units. |
||||||||||||||||||||||||||||||||||||||
style& |
Primary style of the text box control. The default text box style comprises %WS_TABSTOP, %WS_BORDER, %ES_LEFT, and %ES_AUTOHSCROLL. The default style is used if both the primary and extended style parameters are omitted from the statement. For example: CONTROL ADD TEXTBOX, hDlg, id&, txt$, 100, 100, 150, 200, , , _ CALL EditControlCallback() ' Use default styles Custom style values replace the default values. That is, they are not additional to the default style values - your code must specify all necessary primary and extended style parameters. The primary text box style value can be a combination of any values below, combined together with the OR operator to form a bitmask:
|
||||||||||||||||||||||||||||||||||||||
exstyle& |
Extended style of the text box control. The default extended text box style comprises %WS_EX_CLIENTEDGE with %WS_EX_LEFT. The default extended style is used if both the primary and extended parameters are omitted from the CONTROL ADD TEXTBOX statement, in the same manner as style& above. The extended text box style value can be a combination of any values below, combined together with the OR operator to form a bitmask:
|
||||||||||||||||||||||||||||||||||||||
callback |
Optional name of a Callback Function that receives all %WM_COMMAND and %WM_NOTIFY messages for the control. See the #MESSAGES metastatement to choose which messages will be received. If a callback for the control is not designated, you must create a dialog Callback Function to process messages from your control. If the Callback Function processes a message, it should return TRUE (non-zero) to prevent the message being passed unnecessarily to the dialog callback (if one exists). The dialog callback should also return TRUE if the notification message is processed by that Callback Function. Otherwise, the DDT engine processes unhandled messages. |
||||||||||||||||||||||||||||||||||||||
Remarks |
If you specify the %ES_AUTOHSCROLL style, the control automatically scrolls horizontally when the caret goes past the right edge of the control. To start a new line, the user must press the ENTER key. If you do not specify %ES_AUTOHSCROLL, the control automatically wraps words to the beginning of the next line when necessary. A new line is also started if the user presses the ENTER key. The control size determines the position of the word wrap. The following notifications are sent to the Callback Function:
When a Callback Function receives a %WM_COMMAND message, it should explicitly test the value of CB.CTL and CB.CTLMSG to guarantee it is responding appropriately to the notification message. Use CONTROL GET TEXT to retrieve the text from a text box control, and use CONTROL SET TEXT to change the text in a text box control. Changing the text in a text box control (in response to a %EN_CHANGE or %EN_UPDATE message) will trigger a second set of %EN_CHANGE and %EN_UPDATE messages. Unless this is compensated for, these notifications can unwittingly cause an endless loop. For example, the following is potentially fatal: CALLBACK FUNCTION EditControlCallback() IF CB.CTL = %ID_EDITBOX1 AND CB.CTLMSG = %EN_CHANGE THEN CONTROL SET TEXT CB.HNDL, CB.CTL, "New Text" EXIT FUNCTION END IF [statements] As CONTROL SET TEXT is a "blocking" statement (that is, the statement does not complete until the text has been changed), it is a simple matter to block the endless loop effect: CALLBACK FUNCTION EditControlCallback() STATIC EditBusy& IF CB.CTL = %ID_EDITBOX1 AND CB.CTLMSG = %EN_CHANGE THEN IF EditBusy& THEN EXIT FUNCTION EditBusy& = -1 CONTROL SET TEXT CB.HNDL, CB.CTL, "New Text" RESET EditBusy& EXIT FUNCTION END IF [statements] |
||||||||||||||||||||||||||||||||||||||
See also |
Dynamic Dialog Tools, CONTROL GET TEXT, CONTROL SET COLOR, CONTROL SET FONT, CONTROL SET TEXT |